﻿@inherits AntDesignTestBase	
@code {
    AntDesign.TextArea.TextAreaInfo _textAreaInfo = new AntDesign.TextArea.TextAreaInfo
    {
        LineHeight = 10,
        PaddingTop = 1,
        PaddingBottom = 1,
        BorderBottom = 1,
        BorderTop = 1
    };


    private void JSCommonMock()
    {
        JSInterop.SetupVoid(JSInteropConstants.InputComponentHelper.DisposeResizeTextArea, _ => true);   
    }

	[Fact]
	public void TextArea_ShowCount_shows_initial_value()
	{
        //Arrange
        JSCommonMock();
        JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
            .SetResult(_textAreaInfo);
		string value = "0123456789";
		var cut = Render(
    @<AntDesign.TextArea ShowCount MaxLength=100 Value=@value/>);
		//Act
		var divWrapper = cut.Find("div");
		var attribute = divWrapper.GetAttribute("data-count");
		//Assert           
		attribute.Should().Be(value.Length.ToString());		
	}

	[Fact]
	public void TextArea_ShowCount_increase()
	{
		//Arrange	
        JSCommonMock();
        JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
            .SetResult(_textAreaInfo);
		string value = "";
		string newValue = "newValue";
		var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea ShowCount MaxLength=100 Value=@value DebounceMilliseconds="0"/>);
        //Act
        cut.Find("textarea").Input(newValue);
        cut.Find("textarea").KeyUp(String.Empty);
        cut.Render();
        var divWrapper = cut.Find("div");
        var attribute = divWrapper.GetAttribute("data-count");
        //Assert				
        attribute.Should().Be(newValue.Length.ToString());
    }

    [Fact]
    public void TextArea_ReadOnly_creates_attribute()
    {
        //Arrange
        JSCommonMock();
        JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
            .SetResult(_textAreaInfo);
        var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea ReadOnly Value="@("0123456789")"/>);
		//Act
		var textAreaElement = cut.Find("textarea");
		//Assert           
		textAreaElement.HasAttribute("readonly");
	}

	@*[Fact]
	public void TextArea_Rows_creates_with_expected_height()
	{
        //Arrange
        JSCommonMock();
        JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.GetTextAreaInfo, _ => true)
            .SetResult(_textAreaInfo);
        uint rows = 4;
        double expectedHeight = rows * _textAreaInfo.LineHeight +
                            _textAreaInfo.PaddingTop +
                            _textAreaInfo.PaddingBottom +
                            _textAreaInfo.BorderBottom +
                            _textAreaInfo.BorderTop;
        var cut = Render<AntDesign.TextArea>(
        @<AntDesign.TextArea Rows="@rows"/>);
		//Act && Assert
        var textAreaElement = cut.Find("textarea");
        var styleAttribute = textAreaElement.GetAttribute("style");
        styleAttribute.Should().Contain($"height: {expectedHeight}px");
	}*@

	@*[Fact]
	public void TextArea_MinRows_creates_with_expected_height()
	{
        //Arrange
        JSCommonMock();
        JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
            .SetResult(_textAreaInfo);
        uint rows = 4;
        double expectedHeight = rows * _textAreaInfo.LineHeight +
                            _textAreaInfo.PaddingTop +
                            _textAreaInfo.PaddingBottom +
                            _textAreaInfo.BorderBottom +
                            _textAreaInfo.BorderTop;
        var cut = Render<AntDesign.TextArea>(
        @<AntDesign.TextArea MinRows="@rows" Rows="1"/>);
		//Act && Assert
        var textAreaElement = cut.Find("textarea");
        var styleAttribute = textAreaElement.GetAttribute("style");
        styleAttribute.Should().Contain($"height: {expectedHeight}px");
	}*@

	[Fact]
	public void TextArea_AutoSize_is_true_when_MinRows_set()
	{
        //Arrange
        JSCommonMock();
        JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
            .SetResult(_textAreaInfo);
        var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea MinRows="1" AutoSize="false"/>);
        //Act && Assert
        cut.Instance.AutoSize.Should().BeTrue();
	}

	[Fact]
	public void TextArea_AutoSize_is_true_when_MaxRows_set()
	{
        //Arrange
        JSCommonMock();
        JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
            .SetResult(_textAreaInfo);
        var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea MaxRows="4" AutoSize="false"/>);
        //Act && Assert
        cut.Instance.AutoSize.Should().BeTrue();
	}

	@*[Fact]
	public void TextArea_MaxRows_will_take_precedence_over_Rows()
	{
        //Arrange
        JSCommonMock();
        JSInterop.Setup<AntDesign.TextArea.TextAreaInfo>(JSInteropConstants.InputComponentHelper.RegisterResizeTextArea, _ => true)
            .SetResult(_textAreaInfo);
        uint rows = 4;
        double expectedHeight = rows * _textAreaInfo.LineHeight +
                            _textAreaInfo.PaddingTop +
                            _textAreaInfo.PaddingBottom +
                            _textAreaInfo.BorderBottom +
                            _textAreaInfo.BorderTop;

        var cut = Render<AntDesign.TextArea>(@<AntDesign.TextArea Rows="10" MaxRows="@rows"/>);
        //Act && Assert
         var textAreaElement = cut.Find("textarea");
        var styleAttribute = textAreaElement.GetAttribute("style");
        styleAttribute.Should().Contain($"height: {expectedHeight}px");
	}*@
}